package hai.com.android_test.ui;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;
import hai.com.android_test.R;
import hai.com.android_test.ui.fragment.MyFragment;

/**
 * Created by Administrator on 2016/9/9.
 */
public class CalendarActivity extends FragmentActivity{
    private static final String TAG = "Aactivity";
    List<Fragment> list=new ArrayList<>();

    @BindView(R.id.viewPage)
    ViewPager viewPage;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lay_calendar);
        ButterKnife.bind(this);
        for (int i = 0; i <5 ; i++) {
            MyFragment f=new MyFragment();
            Bundle b=new Bundle();
            b.putString("data","fragment:"+i);
            f.setArguments(b);
            list.add(f);
        }
        viewPage.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                Log.e(TAG, "getItem: "+position);
                return list.get(position);
            }

            @Override
            public int getCount() {
//                Log.e(TAG, "getCount: " );
                return Integer.MAX_VALUE;
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                Log.e(TAG, "instantiateItem: "+position);
                return super.instantiateItem(container, position%list.size());
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                Log.e(TAG, "destroyItem: "+position );
                super.destroyItem(container, position%list.size(), object);
            }
        });
        viewPage.setCurrentItem(viewPage.getAdapter().getCount()/2,true);
        viewPage.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
            @Override
            public void onPageSelected(int position) {
                Log.e(TAG, "onPageSelected: "+position );
                super.onPageSelected(position);
            }
        });

    }

}
